var express = require('express');
var router = express.Router();

const categroy = require('../public/data/categroy.json')
const newslist = require('../public/data/newslist.json')
const newsinfo = require('../public/data/newsinfo.json')


/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

/**
 * 获取新闻分类接口
 */

router.get('/getCategroy',(req,res)=>{
  res.send(categroy)
})

/**
 * 获取新闻列表接口
 */

router.get('/getNewsList',(req,res)=>{
  let id = req.query.id
  let newsArr = newslist.result.find(item=>{
    return item.cid == id
  })

  res.send(newsArr)
})

/**
 * 获取新闻详情接口
 */
router.get('/getNewsInfo',(req,res)=>{
  let id = req.query.id
  let newsInfo = newsinfo.list.find(item=>{
    return item.newsid == id
  })
  res.send(newsInfo)
})

module.exports = router;